
from collections import namedtuple
from collections import defaultdict

Result = namedtuple('Result', 'count average')


def averager(): 
    total = 0.0 
    count = 0 
    average = None 
    while True: 
        term = yield average
        if term is None:
            break
        total += term 
        count += 1 
        average = total/count
    return Result(count, average)

def grouper(results, key):
    while True:
        results[key] = yield from averager()


def main():
    data = dict(wangbo=(10,11,12), dongwei=(2,3), wangtianlang=(20,24,56,7))
    results = {}
    for key, values in data.items():
        group = grouper(results, key)
        next(group)
        for value in values:
            group.send(value)
        group.send(None)
    
    print(results)


a_dict = dict(wangbo=1,dongwei=2, wangtianlang=0)

print(a_dict.items())
print(sorted(a_dict))
print(sorted(a_dict.items()))